# wm - kruhft's window manager
#   (C)opyright MMVI Anselm R. Garbe, Burton Samograd

include config.mk

SRC = client.c draw.c event.c main.c tag.c util.c view.c
OBJ = ${SRC:.c=.o}

all: TAGS options wm

options:
	@echo wm build options:
	@echo "CFLAGS   = ${CFLAGS}"
	@echo "LDFLAGS  = ${LDFLAGS}"
	@echo "CC       = ${CC}"
	@echo "LD       = ${LD}"

.c.o:
	@echo CC $<
	${CC} -c ${CFLAGS} $<

${OBJ}: wm.h config.h config.mk

config.h:
	@echo creating $@ from config.default.h
	@cp config.default.h $@

wm: ${OBJ}
	@echo LD $@
	${LD} -o $@ ${OBJ} ${LDFLAGS}
	@strip $@

clean:
	@echo cleaning
	@rm -f wm ${OBJ} wm-${VERSION}.tar.gz

dist: clean
	@echo creating dist tarball
	@mkdir -p wm-${VERSION}
	@cp -R LICENSE Makefile README config.*.h config.mk \
		wm.1 wm.h ${SRC} wm-${VERSION}
	@tar -cf wm-${VERSION}.tar wm-${VERSION}
	@gzip wm-${VERSION}.tar
	@rm -rf wm-${VERSION}

install: all
	@echo installing executable file to ${DESTDIR}${PREFIX}/bin
	@mkdir -p ${DESTDIR}${PREFIX}/bin
	@cp -f wm ${DESTDIR}${PREFIX}/bin
	@chmod 755 ${DESTDIR}${PREFIX}/bin/wm
	@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
	@mkdir -p ${DESTDIR}${MANPREFIX}/man1
	@sed 's/VERSION/${VERSION}/g' < wm.1 > ${DESTDIR}${MANPREFIX}/man1/wm.1
	@chmod 644 ${DESTDIR}${MANPREFIX}/man1/wm.1

uninstall:
	@echo removing executable file from ${DESTDIR}${PREFIX}/bin
	@rm -f ${DESTDIR}${PREFIX}/bin/wm
	@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
	@rm -f ${DESTDIR}${MANPREFIX}/man1/wm.1

TAGS: *.c *.h
	etags *.c *.h

.PHONY: all options clean dist install uninstall

tag.o: tag.c rules.c
